//
//  SecondViewController.m
//  07-界面接传值
//
//  Created by 王道林 on 16/7/22.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "SecondViewController.h"
#import "ViewController.h"

@interface SecondViewController ()
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) UIButton *button;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];
    _textField.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_textField];
    _textField.placeholder = _text;
    _button = [UIButton buttonWithType:UIButtonTypeSystem];
    _button.backgroundColor = [UIColor redColor];
    [self.view addSubview:_button];
    _button.frame = CGRectMake(200, 300, 100, 100);
    [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_button setTitle:@"上一页" forState:UIControlStateNormal];

    
    
}
- (void)buttonAction:(UIButton *)button
{
    
    //属性往回传值
    
//    NSInteger count = self.navigationController.viewControllers.count;
//   ViewController *first = self.navigationController.viewControllers[count -2];
//    first.texttitle = _textField.text;
    
    // 协议 方法 调用
    if ([self.delegate respondsToSelector:@selector(passValue:)]) {
        [self.delegate passValue:_textField.text];
    }
    
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
